<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>选择设备</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lims/css/eleTree.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <style>
        .mbox{
            padding: 8px;
        }
    </style>
</head>
<body>

<div class="mbox">
    <div class="layui-card">
        <div class="layui-card-body" style="padding-left: 6px;">
            <div class="layui-form demoTable" style="display: inline-block;position: absolute;margin-top: 20px;">
                <div class="layui-form-item">
                    <div class="layui-inline" style="margin-top: -28px; margin-left: 50px;">
                        <label  class="layui-form-label" style="width: 86px;margin-top: 9px;">查询字段</label>
                        <div class="layui-input-inline" style="height: 27px;margin-top: 6px;" >
                            <select class="layui-select"  lay-filter="cloum" name="cloum" id="cloum" autocomplete="off" style="margin-top: -5px">
                                <option placeholder="请选择"></option>
                                <option value="EQUIP_NO">设备编码</option>
                                <option value="EQUIP_NAME">设备名称</option>
                                <option value="CODE_TYEP_NAME">设备状况</option>
                                <option value="MODEL_NO">型号</option>
                                <option value="SPEC">规格</option>
                                <option value="MANUFACTURER">生产厂家</option>
                                <option value="SUPPLIER">供应商</option>
                                <option value="PROPERTY_CODE">产权归属</option>
                                <option value="FACTORY_NO">出厂编号</option>
                            </select>
                        </div>
                        <div class=" layui-input-inline"  style="width: 150px;padding-top:5px;box-sizing: border-box">
                            <input type="text" name="price_max" id="fieldVal" placeholder="请输入" autocomplete="off" class="layui-input" style="margin-top: 1px;width:180px;">
                        </div>
                        <div class="layui-input-inline" style="width: 55px;margin-left: 38px">
                            <button id="search" class="layui-btn layui-btn-sm" data-type="reload" lay-event="serch"  style="height: 35px;line-height: 35px;margin-top:8px;width: 70px;">搜索</button>
                        </div>
                    </div>
                </div>
            </div>
            <table id="Settlement" lay-filter="Settlement" lay-data="{id: 'Settlement'}" style="margin-top:50px"></table>
        </div>
    </div>
</div>

<script>
    // 基本信息数据回显
    var equipStatusCode;
    var factoryNo;
    var equipNo;
    var addptId = parent.addseleId  //选择部门得id
    var treeid = parent.equippenter    //下拉树的id
    var typedata  //定义数据表格
    var tableData=parent.childTableData;  //获取父页面选中的设备table
    layui.use(['table','form'], function(){
        var table = layui.table;
        typedata=table;
        var form = layui.form;
        var $ = layui.jquery;
        var equipEventType=parent.parent.$("#equipEventType").val();//equipEventType值
        var tableObj=table.render({
            elem: '#Settlement'
            ,data:[]
            ,url : '/equipment/showEqip?equipTypeId='+treeid+'&deptId='+addptId+'&eventType='+equipEventType
            ,page: false //开启分页
            ,toolbar:'#toolbar'
            ,cols: [[ //表头
                {type: 'checkbox'}
                ,{field: 'equipNo', title: '设备编码'}
                ,{field: 'equipName', title: '设备名称', sort: true}
                ,{field: 'equipStatuasId', title: '设备状态'}
                ,{field:'equipStatusCode',hide:true}
                ,{field: 'modelNo', title: '型号'}
                ,{field: 'spec', title: '规格'}
                ,{field: 'manufacturer', title: '生产厂家'}
                ,{field: 'supplier', title: '供应商'}
                ,{field: 'propertyId', title: '产权归属'}
                ,{field: 'factoryNo', title: '出场编号'}
            ]]
            ,done:function(res){
                if(res.msg=="查询无数据"){
                    $('.layui-table-page').hide()
                }
                if(res.code==0){
                    res.data.forEach(function(item,index){
                        $.each(tableData,function(i){
                            var thisEquipId=tableData[i].equipId;
                            if(item.equipId==thisEquipId){
                                $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true).click();
                                $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked').click();
                                form.render("checkbox");
                            }
                        });
                    })
                }
                form.render();
            }
        });


        /*  ------搜索------*/
        $('#search').click(function(){
            var sele =$('#cloum').val()
            var inp = $('#fieldVal').val()
            // if(sele==''){
            //     layer.msg('请选择查询字段')
            // }else if(inp==''){
            //     layer.msg('搜索关键字不能为空')
            // }else{
            //     tableObj.reload({
            //         url:'/equipment/selectEquipByField',
            //         page:true,
            //         where:{
            //             fieldName:sele,
            //             fieldValue:inp,
            //             equipTypeId:treeid
            //         },
            //         done: function (res) {
            //             layer.msg(res.msg)
            //         }
            //     })
            // }

            if(sele!=''&&inp!=''){
                tableObj.reload({
                    url:'/equipment/selectEquipByField',
                    page:true,
                    where:{
                        fieldName:sele,
                        fieldValue:inp,
                        equipTypeId:treeid
                    },
                    done: function (res) {
                        layer.msg(res.msg)
                    }
                })
            }else{
                tableObj.reload({
                    url:'/equipment/showEqip?equipTypeId='+treeid+'&deptId='+addptId+'&eventType='+equipEventType,
                    page:true,
                    done: function (res) {
                        layer.msg(res.msg)
                    }
                })
            }
        })
        //回车实现搜索
        //下面方法兼容谷歌，火狐，ie:
        document.onkeydown = function (e) {
            var theEvent = window.event || e;
            var code = theEvent.keyCode || theEvent.which;
            if (code == 13) {
                $('#search').click();
            }
        };
    });
</script>
</body>
</html>